<template>
  <div class="play-list">

    <!-- 返回主页 -->
    <div class="nav">
      <router-link to="/">
          <div class="back-icon">
              <img src="../assets/back.svg">
          </div>
      </router-link>
      <h3>歌单</h3>
    </div>

    <!-- 歌单详情 -->
    <section class="header">
        <div class="header-bg" :style="{ 'background-image': 'url(' + this.details.coverImgUrl + ')' }">
        </div>  
        <div class="header-details">
            <div class="details-fl">
                <img :src="this.details.coverImgUrl" />
                <span class="fl-icon">
                    歌单
                </span>
                <i class="listen-num">
                    {{ this.details.playCount | formatNumber }}
                </i>
            </div>
            <div class="details-fr">
                <h2 class="thide2 details-title">
                    {{ this.details.name }}
                </h2>
                <div class="creator thide">
                    <a class="creator-link"  v-if="this.details && this.details.creator">
                        <div class="creator-avatar">
                          <img :src="this.details.creator.avatarUrl" />
                        </div>
                        {{ this.details.creator.nickname }}
                    </a>
                </div>
            </div>
        </div>
    </section>
   

    <!-- 歌单歌曲 -->
    <h3 class="title">歌曲列表</h3>
    <song-item v-if="showSong.length>0" :item="showSong" :playnumber="true"  @play="$emit('play',$event)"></song-item>
    <music-loading v-else></music-loading>
    <div class="more-list" @click="more" >点击查看更多歌曲</div>
    
    <!-- 热门评论 -->
    <h3 class="title">热门评论</h3>
    <comment-list :item="HotComments" v-if="HotComments.length>0">
      <h3 class="title">{{this.HotComments.length==0?'暂无热评':''}}</h3>
    </comment-list>
    <music-loading v-else></music-loading>

    <!-- 评论 -->
    <h3 class="title">最新评论</h3>
    <comment-list :item="showComment" v-if="commentList.length>0"></comment-list>
    <music-loading v-else></music-loading>
    
    <!-- 收藏歌曲 -->
    <div class="ft-fixed">
      <div class="ft-wrap">
        <span class="ft-btn">收藏歌单</span>
      </div>
    </div>

    <router-view></router-view>
  </div>
</template>

<script>
import SongItem from "@/components/SongItem.vue";
import CommentList from "@/components/CommentList.vue"
import MusicLoading from "@/components/MusicLoading.vue"
export default {
  props:[
    "pid"
  ],
  data() {
    return {
      details: [],
      songList: [],
      commentList:[],
      HotComments:[],
      page:1,
    };
  },
  created() {
    this.getPlayList();
    this.getSonglist();
    this.getCommentlist();
  },
  methods: {
    // 获取歌单详情
    async getPlayList() {
      let res = await this.axios.get("/playlist/detail?id=" + this.pid);
      this.details = res.playlist;
    },
    // 获取歌单歌曲列表
    async getSonglist() {
      let res=await this.axios.get("/playlist/track/all?id=" + this.pid)
      let songList = res.songs;
      this.songList = songList.map((song, index) => {
        song.song = {
          album: song.al,
          privilege: res.privileges[index],
          artists: song.ar,
          alias: song.alia,
        };
        return song;
      });
    },
    // 获取歌单评论
    async getCommentlist(){
      let res=await this.axios.get("/comment/playlist?id="+this.pid)
      // console.log("res1",res);
      this.commentList=res.comments
      this.HotComments=res.hotComments
    },
    // 歌单列表分页
    more(){
      this.page++
    }
  },
  filters: {
    formatNumber(value) {
      if (value / 10000 >= 10000) {
        return (value / 100000000).toFixed(1) + "亿";
      } else if (value / 10000 > 0) {
        return (value / 10000).toFixed(1) + "万";
      } else {
        return value;
      }
    },
  },
  computed:{
    showSong(){
      return this.songList.slice(0,20*this.page);
    },
    showComment(){
      return this.commentList.slice(0,20*this.page)
    }
  },
  components: {
    SongItem,
    CommentList,
    MusicLoading,
  },
};
</script>

<style lang="less" scoped>
.play-list {
  position: sticky;
  top: 0px;
  left: 0px;
  z-index: 10;
  width: 100%;
  // margin-top: 40px;
  margin-bottom: 60px;
  .nav{
    position: fixed;
    /* position: absolute; */
    top: 0px;
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
    /* color: #fff; */
    background: white;
    z-index: 2;
    h3{
      height: 20px;
      line-height: 20px;
      padding-left: 10px;
    }
    .back-icon{
        padding-left: 10px;
        width: 20px;
        height: 20px;
        &>img{
            width: 20px;
        }
    }
  }
  .header {
    position: relative;
    padding: 50px 10px 30px 15px;
    overflow: hidden;
    display: flex;
    .header-bg {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      // z-index: 1;
      background-position: 50%;
      background-repeat: no-repeat;
      background-size: cover;
      filter: blur(20px);
      transform: scale(1.5);
      &::after {
        content: " ";
        background-color: rgba(0, 0, 0, 0.25);
      }
    }
    .header-details {
      display: flex;
      z-index: 1;
      height: 126px;
      .details-fl {
        position: relative;
        color: white;
        & > img {
          position: relative;
          width: 126px;
          height: 126px;
        }
        .fl-icon {
          background: red;
          position: absolute;
          top: 10px;
          left: 0;
          padding: 0px 8px;
          height: 17px;
          font-size: 9px;
          border-radius: 0 17px 17px 0;
          z-index: 3;
          text-align: center;
        }
        .listen-num {
          position: absolute;
          top: 0px;
          right: 2px;
          z-index: 3;
          font-size: 12px;
          padding-left: 13px;
          background: url("../assets/listen.svg") no-repeat;
          background-size: 11px 10px;
          background-position: 0;
        }
        &::after {
          content: " ";
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 18px;
          z-index: 2;
          background-image: linear-gradient(
            90deg,
            rgba(0, 0, 0, 0),
            rgba(0, 0, 0, 0.2)
          );
        }
      }
      .details-fr {
        flex: 1 1 auto;
        width: 1%;
        margin-left: 16px;
        color: white;
        .details-title {
          font-size: 17px;
          line-height: 1.3;
          // color: #fefefe;
          height: 44px;
          padding-top: 4px;
        }
        .thide2 {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .creator {
          .creator-link {
            display: flex;
            align-items: center;
            width: 100%;
            // color: hsla(0,0%,100%,.7);
            .creator-avatar {
              width: 30px;
              height: 30px;
              border-radius: 50%;
              vertical-align: middle;
              margin-right: 5px;
              & > img {
                width: 100%;
                border-radius: 50%;
              }
            }
          }
        }
        .thide {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-break: normal;
        }
      }
    }
  }
  .title {
    height: 23px;
    line-height: 23px;
    padding: 0 10px;
    font-size: 12px;
    color: #666;
    background-color: #eeeff0;
  }
  .more-list{
    color: #999;
    font-size: 14px;
    text-align: center;
  }
  .ft-fixed {
    width: 100%;
    position: sticky;
    background-color: #fff;
    bottom: 0px;
    left: 0px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    .ft-wrap {
      display: flex;
      padding: 7px 30px;
      .ft-btn {
        flex: 1 1 auto;
        color: white;
        height: 40px;
        line-height: 40px;
        font-size: 16px;
        background: #ff3a3a;
        border-radius: 36px;
        text-align: center;
        &::before {
          content: "";
          display: inline-block;
          position: relative;
          top: 5px;
          width: 20px;
          height: 20px;
          background: url("../assets/cloud.svg") no-repeat;
          background-size: contain;
          margin-right: 4px;
        }
      }
    }
  }
  
}
</style>